package com.ourteam.system.dao.impl;

import com.ourteam.system.dao.ISysUserLoginLogDAO;
import com.ourteam.system.dao.SysUserLoginLog;
import com.ourteam.system.dao.SysUserLoginLogDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-07-31 15:13:39
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractSysUserLoginLogDAOJdbcImpl extends AbstractSpringDAO
    implements ISysUserLoginLogDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, UserId, SessionId, LoginTime, LoginIp, LogoutTime, OnlineTime,
            OnlineMinute, LastAccessedTime, LoginStatus, UserName, UserAccount,
            UserType, UserStatus
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.UserId,
            _DataObjectProperty.SessionId, _DataObjectProperty.LoginTime,
            _DataObjectProperty.LoginIp, _DataObjectProperty.LogoutTime,
            _DataObjectProperty.OnlineTime, _DataObjectProperty.OnlineMinute,
            _DataObjectProperty.LastAccessedTime,
            _DataObjectProperty.LoginStatus, _DataObjectProperty.UserName,
            _DataObjectProperty.UserAccount, _DataObjectProperty.UserType,
            _DataObjectProperty.UserStatus
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<SysUserLoginLog, SysUserLoginLogDAOQueryBean> daoHelper;

    public AbstractSysUserLoginLogDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<SysUserLoginLog, SysUserLoginLogDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.system.dao.ISysUserDAO.EntityName)
                                .append(" SYS_USER ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.system.dao.ISysUserDAO.Id,
                    com.ourteam.system.dao.ISysUserDAO.EntityName + ".",
                    "SYS_USER."));
            relatedJoinSQLBuffer.append(" = ").append(UserId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aSysUserLoginLog
         * @throws Exception
         */
    public boolean checkIsUnique(SysUserLoginLog aSysUserLoginLog)
        throws Exception {
        if (aSysUserLoginLog == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aSysUserLoginLog.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aSysUserLoginLog
     * @throws Exception
     */
    public void insert(SysUserLoginLog aSysUserLoginLog)
        throws Exception {
        super.doInsert(aSysUserLoginLog);
    }

    /**
         * Batch Insert Datas
         * @param aSysUserLoginLog
         * @throws Exception
         */
    public void batchInsert(SysUserLoginLog[] aSysUserLoginLogs)
        throws Exception {
        super.doBatchInsert(aSysUserLoginLogs);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(SysUserLoginLogDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(SysUserLoginLog aSysUserLoginLog)
        throws Exception {
        delete(aSysUserLoginLog.getId());
    }

    /**
     * Update Data Selective
     * @param aSysUserLoginLog
     * @throws Exception
     */
    public void update(SysUserLoginLog aSysUserLoginLog)
        throws Exception {
        if (aSysUserLoginLog.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aSysUserLoginLog);

        SysUserLoginLog tempObj = findById(aSysUserLoginLog.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aSysUserLoginLog, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aSysUserLoginLogs[]
     * @throws Exception
     */
    public void batchUpdate(SysUserLoginLog[] aSysUserLoginLogs)
        throws Exception {
        super.doBatchUpdate(aSysUserLoginLogs);
    }

    /**
         * Update Data By Condictions
         * @param aSysUserLoginLog
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(SysUserLoginLog aSysUserLoginLog,
        SysUserLoginLogDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aSysUserLoginLog, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(SysUserLoginLogDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(SysUserLoginLog aSysUserLoginLog)
        throws Exception {
        if (aSysUserLoginLog.getLastAccessedTime() == null) {
            throw new Exception(
                "The SysUserLoginLog.lastAccessedTime value is not allow NULL");
        }

        if (aSysUserLoginLog.getLoginStatus() == null) {
            throw new Exception(
                "The SysUserLoginLog.loginStatus value is not allow NULL");
        }

        if (aSysUserLoginLog.getSessionId() == null) {
            throw new Exception(
                "The SysUserLoginLog.sessionId value is not allow NULL");
        }

        if (aSysUserLoginLog.getLoginTime() == null) {
            throw new Exception(
                "The SysUserLoginLog.loginTime value is not allow NULL");
        }

        if (aSysUserLoginLog.getLoginIp() == null) {
            throw new Exception(
                "The SysUserLoginLog.loginIp value is not allow NULL");
        }

        if (aSysUserLoginLog.getLogoutTime() == null) {
            throw new Exception(
                "The SysUserLoginLog.logoutTime value is not allow NULL");
        }

        if (aSysUserLoginLog.getUserName() == null) {
            throw new Exception(
                "The SysUserLoginLog.userName value is not allow NULL");
        }

        if (aSysUserLoginLog.getUserType() == null) {
            throw new Exception(
                "The SysUserLoginLog.userType value is not allow NULL");
        }

        if (aSysUserLoginLog.getUserAccount() == null) {
            throw new Exception(
                "The SysUserLoginLog.userAccount value is not allow NULL");
        }

        if (aSysUserLoginLog.getUserStatus() == null) {
            throw new Exception(
                "The SysUserLoginLog.userStatus value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public SysUserLoginLog findById(final long id) throws Exception {
        SysUserLoginLogDAOQueryBean queryBean = new SysUserLoginLogDAOQueryBean();

        SysUserLoginLogDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        SysUserLoginLog[] SysUserLoginLogs = query(queryBean);

        if (SysUserLoginLogs.length == 0) {
            return null;
        } else {
            return SysUserLoginLogs[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return SysUserLoginLog[]
         * @throws Exception
         */
    public SysUserLoginLog[] query(SysUserLoginLogDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcSysUserLoginLogRowMapper());

        return (SysUserLoginLog[]) result.toArray(new SysUserLoginLog[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        SysUserLoginLogDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(SysUserLoginLogDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(SysUserLoginLog[] aSysUserLoginLogs,
        SysUserLoginLogDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aSysUserLoginLogs, queryBean);
    }

    public void synchronize(SysUserLoginLog[] aSysUserLoginLogs,
        SysUserLoginLogDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<SysUserLoginLog> callBack)
        throws Exception {
        daoHelper.synchronize(aSysUserLoginLogs, queryBean, callBack);
    }

    public static class JdbcSysUserLoginLogRowMapper implements RowMapper<SysUserLoginLog> {
        public SysUserLoginLog mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            SysUserLoginLog object = new SysUserLoginLog();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object userId = null;

                userId = resultSet.getObject(columnIndex++);

                object.setUserIdNull(resultSet.getBoolean(columnIndex++));

                if (userId != null) {
                    setBeanValue(object, _DataObjectProperty.UserId, userId);
                }

                Object sessionId = null;

                sessionId = resultSet.getObject(columnIndex++);

                object.setSessionIdNull(resultSet.getBoolean(columnIndex++));

                if (sessionId != null) {
                    setBeanValue(object, _DataObjectProperty.SessionId,
                        sessionId);
                }

                Object loginTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    loginTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    loginTime = resultSet.getObject(columnIndex++);
                }

                object.setLoginTimeNull(resultSet.getBoolean(columnIndex++));

                if (loginTime != null) {
                    setBeanValue(object, _DataObjectProperty.LoginTime,
                        loginTime);
                }

                Object loginIp = null;

                loginIp = resultSet.getObject(columnIndex++);

                object.setLoginIpNull(resultSet.getBoolean(columnIndex++));

                if (loginIp != null) {
                    setBeanValue(object, _DataObjectProperty.LoginIp, loginIp);
                }

                Object logoutTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    logoutTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    logoutTime = resultSet.getObject(columnIndex++);
                }

                object.setLogoutTimeNull(resultSet.getBoolean(columnIndex++));

                if (logoutTime != null) {
                    setBeanValue(object, _DataObjectProperty.LogoutTime,
                        logoutTime);
                }

                Object onlineTime = null;

                onlineTime = resultSet.getObject(columnIndex++);

                object.setOnlineTimeNull(resultSet.getBoolean(columnIndex++));

                if (onlineTime != null) {
                    setBeanValue(object, _DataObjectProperty.OnlineTime,
                        onlineTime);
                }

                Object onlineMinute = null;

                onlineMinute = resultSet.getObject(columnIndex++);

                object.setOnlineMinuteNull(resultSet.getBoolean(columnIndex++));

                if (onlineMinute != null) {
                    setBeanValue(object, _DataObjectProperty.OnlineMinute,
                        onlineMinute);
                }

                Object lastAccessedTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    lastAccessedTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    lastAccessedTime = resultSet.getObject(columnIndex++);
                }

                object.setLastAccessedTimeNull(resultSet.getBoolean(
                        columnIndex++));

                if (lastAccessedTime != null) {
                    setBeanValue(object, _DataObjectProperty.LastAccessedTime,
                        lastAccessedTime);
                }

                Object loginStatus = null;

                loginStatus = resultSet.getObject(columnIndex++);

                object.setLoginStatusNull(resultSet.getBoolean(columnIndex++));

                if (loginStatus != null) {
                    setBeanValue(object, _DataObjectProperty.LoginStatus,
                        loginStatus);
                }

                Object userName = null;

                userName = resultSet.getObject(columnIndex++);

                object.setUserNameNull(resultSet.getBoolean(columnIndex++));

                if (userName != null) {
                    setBeanValue(object, _DataObjectProperty.UserName, userName);
                }

                Object userAccount = null;

                userAccount = resultSet.getObject(columnIndex++);

                object.setUserAccountNull(resultSet.getBoolean(columnIndex++));

                if (userAccount != null) {
                    setBeanValue(object, _DataObjectProperty.UserAccount,
                        userAccount);
                }

                Object userType = null;

                userType = resultSet.getObject(columnIndex++);

                object.setUserTypeNull(resultSet.getBoolean(columnIndex++));

                if (userType != null) {
                    setBeanValue(object, _DataObjectProperty.UserType, userType);
                }

                Object userStatus = null;

                userStatus = resultSet.getObject(columnIndex++);

                object.setUserStatusNull(resultSet.getBoolean(columnIndex++));

                if (userStatus != null) {
                    setBeanValue(object, _DataObjectProperty.UserStatus,
                        userStatus);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
